package com.gmscosmo.janus.handler;

import com.gmscosmo.model.RtpForwardData;
import com.gmscosmo.model.Subscriber;

/**
 *
 * ClassName: JanusStreamingHandler
 * Description: 
 * Date: 2021/10/12 10:57
 * @author stephen.qiu
 * @version 1.0
 *
 */
public abstract class JanusStreamingHandler extends JanusHandler {
    /**
     * 创建流接受
     * @param session_id
     * @param handle_id
     * @param display
     * @param streamId
     * @param rtpForwardData
     * @param userId
     * @param nodeId
     * @return
     * @throws Exception
     */
    public abstract String createStream(long session_id, long handle_id, String display, int streamId, RtpForwardData rtpForwardData, String userId, int nodeId) throws Exception;


    /**
     * 销毁流
     * @param userId
     * @throws Exception
     */
    public abstract void destroyMyStream(String userId) throws Exception;

    /**
     * 选择观看流
     * @param session_id
     * @param handle_id
     * @param id
     * @param nodeId
     * @return
     * @throws Exception
     */
    public abstract String watch(long session_id, long handle_id, Integer id, int nodeId) throws Exception;

    /**
     * 添加消费者
     * @param session_id
     * @param handle_id
     * @param display
     * @param streamId
     * @param rtpForwardData
     * @param userId
     */
    protected void addSubcriber(long session_id,long handle_id,String display, int streamId,RtpForwardData rtpForwardData,String userId) {
        Subscriber subscriber = new Subscriber();
        subscriber.setSession_id(session_id);
        subscriber.setHandle_id(handle_id);
        subscriber.setAudio_port(rtpForwardData.getAudio_port());
        subscriber.setVideo_port(rtpForwardData.getVideo_port());
        subscriber.setVideo_port_2(rtpForwardData.getVideo_port_2());
        subscriber.setVideo_port_3(rtpForwardData.getVideo_port_3());
        subscriber.setId(streamId);
        subscriber.setSubscriberFrom(display);
        subscriber.setVideo_rtcp_port(rtpForwardData.getVideo_rtcp_port());
        janusUtil.putSubscribers(userId, subscriber);
    }
}
